import { Injectable } from '@angular/core';
import { Profile } from '../../framework/login/models/profile.model';
import { Claims } from '../models/claims.model';

@Injectable()
export class StorageService {   
    
    //this storage element is overwritten on token expiration. Must be directly read from localStorage because
    get authData(): any{
        return JSON.parse(localStorage.getItem('sust:a'));
    }

    public resourcePermissions: Claims[]; 

    public userInfo: Profile;

    constructor(){  
        this.resourcePermissions = JSON.parse(localStorage.getItem('sust:a:claims'));
        this.userInfo = JSON.parse(localStorage.getItem('sust:a:user'));
    }

    private static _instance: StorageService = null;

    public static get(): StorageService{
        if(StorageService._instance === null)
            StorageService._instance = new StorageService();
        return StorageService._instance;
    }
}